package engine.game.hud;

import engine.entities.Entity;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.Insets;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.border.Border;

import engine.entities.Player;
import engine.game.Tickable;

public class Sidebar extends JPanel implements Tickable {

    private static final long serialVersionUID = 1L;

    private ChatBox chat;
    private StatBlockViewer viewer;
    private Border border;

    private JPanel chatHolder;
    private JPanel viewerHolder;

    public Sidebar(Player player) {
        this.setLayout(new GridLayout(2, 1));
        chat = new ChatBox();
        viewer = new StatBlockViewer(player);

        chatHolder = new JPanel(new BorderLayout());

        Border raisedBevel = BorderFactory.createRaisedBevelBorder();
        Border loweredBevel = BorderFactory.createLoweredBevelBorder();
        border = BorderFactory.createCompoundBorder(raisedBevel, loweredBevel);

        chatHolder.setBorder(border);
        chatHolder.add(chat, BorderLayout.CENTER);

        viewerHolder = new JPanel(new BorderLayout());
        viewerHolder.setBorder(border);
        viewerHolder.add(viewer, BorderLayout.CENTER);

        this.add(viewerHolder);
        this.add(chatHolder);

    }

    public Insets borderInsets() {
        return border.getBorderInsets(this);
    }
    
    public void setViewerEntity(Entity ent) {
        viewer.setEntity(ent);
    }

    public Entity getViewerEntity() {
        return viewer.getEntity();
    }
    
    @Override
    public void tick() {
        viewer.tick();
    }
    
}
